package com.jiliang.jiliangserver.controller;


import com.jiliang.jiliangserver.annotation.Log;
import com.jiliang.jiliangserver.domain.*;
import com.jiliang.jiliangserver.enums.BusinessType;
import com.jiliang.jiliangserver.model.AjaxResult;
import com.jiliang.jiliangserver.model.page.TableDataInfo;
import com.jiliang.jiliangserver.service.MaterialService;
import com.jiliang.jiliangserver.service.MeterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/material")
@Slf4j
public class MaterialController extends BaseController {

    @Autowired
    private MaterialService materialService;

    /**
     * 新增电池
     * @param battery
     * @return
     */
    @Log(title = "新增电池", businessType = BusinessType.INSERT)
    @PostMapping("/createBattery")
    public AjaxResult createBattery(@RequestBody Battery battery)throws Exception{
        materialService.createBattery(battery);
        return AjaxResult.success();
    }

    /**
     * 创建品牌
     * @param brand
     * @return
     */
    @Log(title = "创建品牌", businessType = BusinessType.INSERT)
    @PostMapping("/createBrand")
    public AjaxResult createBrand(@RequestBody Brand brand) throws Exception{
        materialService.createBrand(brand);
        return AjaxResult.success();
    }

    /**
     * 根据id查询品牌
     * @param id
     * @return
     */
    @GetMapping("/selectBrandById")
    public AjaxResult selectBrandById(Long id) throws Exception{
        Brand brand = materialService.selectBrandById(id);
        return AjaxResult.success(brand);
    }

    /**
     * 条件查询品牌
     * @param brand
     * @return
     */
    @GetMapping("/selectBrandList")
    public AjaxResult selectBrandList(Brand brand) throws Exception{
        List<Brand> brands = materialService.selectBrandList(brand);
        return AjaxResult.success(brands);
    }

    /**
     * 根据id查询电池
     * @param id
     * @return
     */
    @GetMapping("/selectBatteryById")
    public AjaxResult selectBatteryById(Long id) throws Exception{
        Battery battery = materialService.selectBatteryById(id);
        return AjaxResult.success(battery);
    }

    /**
     * 条件查询电池
     * @param battery
     * @return
     */
    @GetMapping("/selectBatteryList")
    public AjaxResult selectBatteryList(Battery battery) throws Exception{
        List<Battery> batterys = materialService.selectBatteryList(battery);
        return AjaxResult.success(batterys);
    }

    /**
     * 电池品牌数量统计
     * @param battery
     * @return
     */
    @GetMapping("/selectBatteryBrandCounts")
    public AjaxResult selectBatteryBrandCounts(Battery battery) throws Exception{
        List<Map> maps = materialService.selectBatteryBrandCounts(battery);
        return AjaxResult.success(maps);
    }

    /**
     * 更换电池
     * @param materialLog
     * @return
     * @throws Exception
     */
    @Log(title = "更换电池", businessType = BusinessType.UPDATE)
    @PutMapping("/changeBattery")
    public AjaxResult changeBattery(@RequestBody MaterialLog materialLog) throws Exception{
        materialService.changeBattery(materialLog);
        return AjaxResult.success();
    }


    /**
     * 创建sim卡
     * @param simcard
     * @return
     */
    @Log(title = "创建sim卡", businessType = BusinessType.INSERT)
    @PostMapping("/createSimcard")
    public AjaxResult createSimcard(@RequestBody Simcard simcard) throws Exception{
        materialService.createSimcard(simcard);
        return AjaxResult.success();
    }




    /**
     * 根据id查询sim卡
     * @param id
     * @return
     */
    @GetMapping("/selectSimcardById")
    public AjaxResult selectSimcardById(Long id) throws Exception{
        Simcard simcard = materialService.selectSimcardById(id);
        return AjaxResult.success(simcard);
    }

    /**
     * 条件查询sim卡
     * @param
     * @return
     */
    @GetMapping("/selectSimcardList")
    public AjaxResult selectSimcardList(Simcard simcard) throws Exception{
        List<Simcard> simcards = materialService.selectSimcardList(simcard);
        return AjaxResult.success(simcards);
    }

    /**
     * 修改sim卡
     * @param
     * @return
     * @throws Exception
     */
    @Log(title = "修改sim卡", businessType = BusinessType.UPDATE)
    @PutMapping("/updateSimcard")
    public AjaxResult updateSimcard(@RequestBody Simcard simcard) throws Exception{
        materialService.updateSimcard(simcard);
        return AjaxResult.success();
    }


    /**
     * 创建型号
     * @param jlModel
     * @return
     */
    @Log(title = "创建型号", businessType = BusinessType.INSERT)
    @PostMapping("/createJlModel")
    public AjaxResult createJlModel(@RequestBody JlModel jlModel) throws Exception{
        materialService.createJlModel(jlModel);
        return AjaxResult.success();
    }


    /**
     * 根据id查询型号
     * @param id
     * @return
     */
    @GetMapping("/selectJlModelById")
    public AjaxResult selectJlModelById(Long id) throws Exception{
        JlModel jlModel = materialService.selectJlModelById(id);
        return AjaxResult.success(jlModel);
    }

    /**
     * 条件查询型号
     * @param
     * @return
     */
    @GetMapping("/selectJlModelList")
    public AjaxResult selectJlModelList(JlModel jlModel) throws Exception{
        List<JlModel> jlModels = materialService.selectJlModelList(jlModel);
        return AjaxResult.success(jlModels);
    }

    /**
     * 修改型号
     * @param
     * @return
     * @throws Exception
     */
    @Log(title = "修改型号", businessType = BusinessType.UPDATE)
    @PutMapping("/updateJlModel")
    public AjaxResult updateJlModel(@RequestBody JlModel jlModel) throws Exception{
        materialService.updateJlModel(jlModel);
        return AjaxResult.success();
    }


    /**
     * 创建用水性质
     * @param waterUse
     * @return
     */
    @Log(title = "创建用水性质", businessType = BusinessType.INSERT)
    @PostMapping("/createWaterUse")
    public AjaxResult createWaterUse(@RequestBody WaterUse waterUse) throws Exception{
        materialService.createWaterUse(waterUse);
        return AjaxResult.success();
    }


    /**
     * 根据id查询用水性质
     * @param id
     * @return
     */
    @GetMapping("/selectWaterUseById")
    public AjaxResult selectWaterUseById(Long id) throws Exception{
        WaterUse waterUse = materialService.selectWaterUseById(id);
        return AjaxResult.success(waterUse);
    }

    /**
     * 条件查询用水性质
     * @param
     * @return
     */
    @GetMapping("/selectWaterUselList")
    public AjaxResult selectWaterUselList(WaterUse waterUse) throws Exception{
        List<WaterUse> waterUseList = materialService.selectWaterUseList(waterUse);
        return AjaxResult.success(waterUseList);
    }

    /**
     * 修改用水性质
     * @param
     * @return
     * @throws Exception
     */
    @Log(title = "修改用水性质", businessType = BusinessType.UPDATE)
    @PutMapping("/updateWaterUse")
    public AjaxResult updateWaterUse(@RequestBody WaterUse waterUse) throws Exception{
        materialService.updateWaterUse(waterUse);
        return AjaxResult.success();
    }


    /**
     * 创建远传模板
     * @param ycTemplate
     * @return
     */
    @Log(title = "创建远传模板", businessType = BusinessType.INSERT)
    @PostMapping("/createYcTemplate")
    public AjaxResult createYcTemplate(@RequestBody YcTemplate ycTemplate) throws Exception{
        materialService.createYcTemplate(ycTemplate);
        return AjaxResult.success();
    }


    /**
     * 根据id查询远传模板
     * @param id
     * @return
     */
    @GetMapping("/selectYcTemplateById")
    public AjaxResult selectYcTemplateById(Long id) throws Exception{
        YcTemplate ycTemplate = materialService.selectYcTemplateById(id);
        return AjaxResult.success(ycTemplate);
    }

    /**
     * 条件查询远传模板
     * @param
     * @return
     */
    @GetMapping("/selectYcTemplateList")
    public AjaxResult selectYcTemplateList(YcTemplate ycTemplate) throws Exception{
        List<YcTemplate> ycTemplateList = materialService.selectYcTemplateList(ycTemplate);
        return AjaxResult.success(ycTemplateList);
    }

    /**
     * 修改远传模板
     * @param
     * @return
     * @throws Exception
     */
    @Log(title = "修改远传模板", businessType = BusinessType.UPDATE)
    @PutMapping("/updateYcTemplate")
    public AjaxResult updateYcTemplate(@RequestBody YcTemplate ycTemplate) throws Exception{
        materialService.updateYcTemplate(ycTemplate);
        return AjaxResult.success();
    }


}






